//#include  "unp.h"                                                                                                                                                                         
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#include    <time.h>


#define MAXLINE 4096
#define PORT 13
#define SA struct sockaddr
#define LISTENQ 5
int
main(int argc, char **argv)
{
    int                 listenfd, connfd;
    struct sockaddr_in  servaddr;
    char                buff[MAXLINE];
    time_t              ticks;


    listenfd = socket(AF_INET, SOCK_STREAM, 0); 


    bzero(&servaddr, sizeof(servaddr));
    servaddr.sin_family      = AF_INET;
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
    servaddr.sin_port        = htons(13);   /* daytime server */
    bind(listenfd, (SA *) &servaddr, sizeof(servaddr));


    listen(listenfd, LISTENQ);


    for ( ; ; ) { 
        connfd = accept(listenfd, (SA *) NULL, NULL);
        printf("connected!\n");
        ticks = time(NULL);
        snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
        write(connfd, buff, strlen(buff));
        close(connfd);
    }   
}
